// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CLOUDAPPENGINE_CAEHTTPSJOBTHREAD_H
#define CLOUDAPPENGINE_CAEHTTPSJOBTHREAD_H

#include <queue>
#include "CaeHttpsJob.h"
#include "../cae_common/CaeThread.h"

struct HttpsJobInfo {
public:
    HttpsJobInfo()
    {
        this->m_jobId = 0;
        this->m_job = JOB_TYPE_MAX;
    };

    ~HttpsJobInfo() {};

    uint16_t GetJobType()
    {
        return this->m_job;
    }

    void SetJobId(uint16_t jobId)
    {
        this->m_jobId = jobId;
    }

    uint16_t GetJobId()
    {
        return this->m_jobId;
    }

    void SetJobType(HttpsJobType job)
    {
        this->m_job = job;
    }

private:
    HttpsJobType m_job;
    uint16_t m_jobId;
};

class CaeHttpsJobThread : public CaeThread {
public:
    CaeHttpsJobThread();

    ~CaeHttpsJobThread() override;

    void Run() override;

    int AddHttpsJob(HttpsJobType httpsJobType);

    uint16_t GetCurrentJobId();

private:
    pthread_mutex_t m_jobsLock;
    queue<HttpsJobInfo *> m_jobs;
    uint16_t m_currentJobId;
};

#endif // CLOUDAPPENGINE_CAEHTTPSJOBTHREAD_H
